{% extends 'base.html' %}
{% load buttons %}
{% load custom_links %}
{% load helpers %}
{% load plugins %}

{% block header %}
    <div class="row noprint">
        <div class="col-sm-8 col-md-9">
            <ol class="breadcrumb">
                <li><a href="{% url 'ipam:vlan_list' %}">VLANs</a></li>
                {% if vlan.site %}
                    <li><a href="{% url 'ipam:vlan_list' %}?site={{ vlan.site.slug }}">{{ vlan.site }}</a></li>
                {% endif %}
                {% if vlan.group %}
                    <li><a href="{% url 'ipam:vlan_list' %}?group={{ vlan.group.slug }}">{{ vlan.group }}</a></li>
                {% endif %}
                <li>{{ vlan }}</li>
            </ol>
        </div>
        <div class="col-sm-4 col-md-3">
        <form action="{% url 'ipam:vlan_list' %}" method="get">
            <div class="input-group">
                <input type="text" name="q" class="form-control" placeholder="Search VLANs" />
                <span class="input-group-btn">
                    <button type="submit" class="btn btn-primary">
                        <span class="fa fa-search" aria-hidden="true"></span>
                    </button>
                </span>
            </div>
        </form>
        </div>
    </div>
    <div class="pull-right noprint">
        {% plugin_buttons vlan %}
        {% if perms.ipam.add_vlan %}
            {% clone_button vlan %}
        {% endif %}
        {% if perms.ipam.change_vlan %}
            {% edit_button vlan %}
        {% endif %}
        {% if perms.ipam.delete_vlan %}
            {% delete_button vlan %}
        {% endif %}
    </div>
    <h1>{% block title %}VLAN {{ vlan.display_name }}{% endblock %}</h1>
    {% include 'inc/created_updated.html' with obj=vlan %}
    <div class="pull-right noprint">
        {% custom_links vlan %}
    </div>
    <ul class="nav nav-tabs" style="margin-bottom: 20px">
        <li role="presentation"{% if not active_tab %} class="active"{% endif %}>
            <a href="{% url 'ipam:vlan' pk=vlan.pk %}">VLAN</a>
        </li>
        <li role="presentation"{% if active_tab == 'interfaces' %} class="active"{% endif %}>
            <a href="{% url 'ipam:vlan_interfaces' pk=vlan.pk %}">Device Interfaces <span class="badge">{{ vlan.get_interfaces.count }}</span></a>
        </li>
        <li role="presentation"{% if active_tab == 'vminterfaces' %} class="active"{% endif %}>
            <a href="{% url 'ipam:vlan_vminterfaces' pk=vlan.pk %}">VM Interfaces <span class="badge">{{ vlan.get_vminterfaces.count }}</span></a>
        </li>
        {% if perms.extras.view_objectchange %}
            <li role="presentation"{% if active_tab == 'changelog' %} class="active"{% endif %}>
                <a href="{% url 'ipam:vlan_changelog' pk=vlan.pk %}">Change Log</a>
            </li>
        {% endif %}
    </ul>
{% endblock %}

{% block content %}
    <div class="row">
        <div class="col-md-4">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <strong>VLAN</strong>
                </div>
                <table class="table table-hover panel-body attr-table">
                    <tr>
                        <td>Site</td>
                        <td>
                            {% if vlan.site %}
                                {% if vlan.site.region %}
                                    <a href="{{ vlan.site.region.get_absolute_url }}">{{ vlan.site.region }}</a>
                                    <i class="fa fa-angle-right"></i>
                                {% endif %}
                                <a href="{% url 'dcim:site' slug=vlan.site.slug %}">{{ vlan.site }}</a>
                            {% else %}
                                <span class="text-muted">None</span>
                            {% endif %}
                        </td>
                    </tr>
                    <tr>
                        <td>Group</td>
                        <td>
                            {% if vlan.group %}
                                <a href="{{ vlan.group.get_absolute_url }}">{{ vlan.group }}</a>
                            {% else %}
                                <span class="text-muted">None</span>
                            {% endif %}
                        </td>
                    </tr>
                    <tr>
                        <td>VLAN ID</td>
                        <td>{{ vlan.vid }}</td>
                    </tr>
                    <tr>
                        <td>Name</td>
                        <td>{{ vlan.name }}</td>
                    </tr>
                    <tr>
                        <td>Tenant</td>
                        <td>
                            {% if vlan.tenant %}
                                {% if vlan.tenant.group %}
                                    <a href="{{ vlan.tenant.group.get_absolute_url }}">{{ vlan.tenant.group }}</a>
                                    <i class="fa fa-angle-right"></i>
                                {% endif %}
                                <a href="{{ vlan.tenant.get_absolute_url }}">{{ vlan.tenant }}</a>
                            {% else %}
                                <span class="text-muted">None</span>
                            {% endif %}
                        </td>
                    </tr>
                    <tr>
                        <td>Status</td>
                        <td>
                            <span class="label label-{{ vlan.get_status_class }}">{{ vlan.get_status_display }}</span>
                        </td>
                    </tr>
                    <tr>
                        <td>Role</td>
                        <td>
                            {% if vlan.role %}
                                <a href="{% url 'ipam:vlan_list' %}?role={{ vlan.role.slug }}">{{ vlan.role }}</a>
                            {% else %}
                                <span class="text-muted">None</span>
                            {% endif %}
                        </td>
                    </tr>
                    <tr>
                        <td>Description</td>
                        <td>{{ vlan.description|placeholder }}</td>
                    </tr>
                </table>
            </div>
            {% include 'inc/custom_fields_panel.html' with obj=vlan %}
            {% include 'extras/inc/tags_panel.html' with tags=vlan.tags.all url='ipam:vlan_list' %}
            {% plugin_left_page vlan %}
        </div>
        <div class="col-md-8">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <strong>Prefixes</strong>
                </div>
                {% include 'responsive_table.html' with table=prefix_table %}
                {% if perms.ipam.add_prefix %}
                    <div class="panel-footer text-right noprint">
                        <a href="{% url 'ipam:prefix_add' %}?{% if vlan.tenant %}tenant={{ vlan.tenant.pk }}&{% endif %}site={{ vlan.site.pk }}&vlan={{ vlan.pk }}" class="btn btn-primary btn-xs">
                            <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
                            Add a prefix
                        </a>
                    </div>
                {% endif %}
            </div>
            {% plugin_right_page vlan %}
        </div>
    </div>
    <div class="row">
        <div class="col-md-12">
            {% plugin_full_width_page vlan %}
        </div>
    </div>
{% endblock %}
